<template>
  <div class="wishlist">
    <h1>我的愿望清单</h1>
    
    <div v-if="wishlistWeapons.length === 0" class="empty-wishlist">
      <p>还没有添加想要的军火</p>
      <router-link to="/arsenal" class="browse-link">浏览军火</router-link>
    </div>

    <div v-else class="weapons-grid">
      <div v-for="weapon in wishlistWeapons" :key="weapon.id" class="weapon-card">
        <div class="weapon-image">
          <img :src="weapon.image" :alt="weapon.name" @error="handleImageError">
          <button 
            class="wishlist-btn active"
            @click="toggleWishlist(weapon.id)"
          >
            <svg viewBox="0 0 24 24" class="heart-icon">
              <path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/>
            </svg>
          </button>
        </div>
        <div class="weapon-info">
          <h3>{{ weapon.name }}</h3>
          <p>{{ weapon.type }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'

export default {
  name: 'Wishlist',
  setup() {
    const store = useStore()

    const wishlistWeapons = computed(() => store.getters.wishlistWeapons)

    const toggleWishlist = (weaponId) => {
      store.dispatch('toggleWishlistItem', weaponId)
    }

    const handleImageError = (e) => {
      e.target.src = '/placeholder.png'
    }

    return {
      wishlistWeapons,
      toggleWishlist,
      handleImageError
    }
  }
}
</script>

<style scoped>
.wishlist {
  padding: 80px 2rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

h1 {
  text-align: center;
  color: #ff4655;
  margin-bottom: 2rem;
}

.empty-wishlist {
  text-align: center;
  padding: 3rem;
  background-color: #1f1f1f;
  border-radius: 8px;
  color: #666;
}

.browse-link {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.75rem 2rem;
  background-color: #ff4655;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.browse-link:hover {
  background-color: #e6323f;
}

.weapons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 2rem;
  padding: 1rem;
}

.weapon-card {
  background-color: #1f1f1f;
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.3s;
}

.weapon-card:hover {
  transform: translateY(-5px);
}

.weapon-image {
  position: relative;
  height: 200px;
}

.weapon-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wishlist-btn {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  transition: transform 0.2s;
  z-index: 2;
}

.wishlist-btn:hover {
  transform: scale(1.1);
}

.heart-icon {
  width: 24px;
  height: 24px;
  fill: #ff4655;
  stroke: #ff4655;
  stroke-width: 2;
}

.weapon-info {
  padding: 1rem;
}

.weapon-info h3 {
  color: white;
  margin: 0 0 0.5rem;
}

.weapon-info p {
  color: #ff4655;
  margin: 0;
}
</style> 